import createContextMenu, { ActionItem } from '@/components/createContextMenu'
import { useEditorStore } from '@/stores/editor'

export default function initContextMenu() {
  const store = useEditorStore()
  const testActions: ActionItem[] = [
    {
      shortcut: 'Ctrl + C / Command + C',
      text: '复制图层',
      action: componentId => {
        store.copyComponent(componentId)
      }
    },
    {
      shortcut: 'Backspace / Delete',
      text: '删除图层',
      action: componentId => {
        store.deleteComponent(componentId)
      }
    }
  ]

  let destroy: any
  onMounted(() => {
    destroy = createContextMenu(testActions)
  })

  onUnmounted(() => {
    if (destroy) {
      destroy()
    }
  })
}
